package com.vr.xuecheng.content.controller;

import com.vr.xuecheng.base.response.Result;
import com.vr.xuecheng.content.model.dto.SaveOrUpdateTeacherDTO;
import com.vr.xuecheng.content.model.entity.CourseTeacher;
import com.vr.xuecheng.content.service.ICourseTeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hzh
 * @date 2025/03/16
 * 教师课程
 */
@Slf4j
@RestController
@Tag(name = "教师课程")
@RequestMapping("/courseTeacher")
@RequiredArgsConstructor
public class CourseTeacherController {
    private final ICourseTeacherService courseTeacherService;


    @Operation(summary = "根据课程id查询教师列表")
    @GetMapping("/list/{course-id}")
    public List<CourseTeacher> listByCourseId(@PathVariable("course-id") Long courseId) {
        return courseTeacherService.lambdaQuery()
                .eq(courseId != null, CourseTeacher::getCourseId, courseId)
                .list();
    }

    /**
     * @param req 保存或修改教师信息
     * @return {@code Result<String> }
     * 保存或修改教师信息
     */
    @Operation(summary = "保存或修改教师信息")
    @PostMapping
    public Result<String> saveOrUpdate(@RequestBody SaveOrUpdateTeacherDTO req) {
        return Result.toResult(req.getId()==null?courseTeacherService.save(req):courseTeacherService.updateById(req));
    }
}
